home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Just Call Me Internet
/
Just Call Me Internet.iso
/
com
/
othernet
/
fidonet
/
raw_nl1
/
mkrawidx.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-25
|
4KB
|
169 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ext.h>
#include <tos.h>
#include <portab.h>
#include <defines.h>
#define VERSION "0.01"
static uword parse_list(FILE *fp,ubyte *src,uword nlnumber,uword defzone,uword pointlist);
static void new_entry(FILE *out,ulong offset,uword zone,uword net,uword node,uword point);
HEADER header;
NLHEADER nlheader;
ENTRY entry;
int main(int argc,char *argv[])
{ int i;
FILE *fp;
--argc;
if (argc<1)
{ fprintf(stderr,"MKRAWIDX V"VERSION" Nodelist-Utility (Demo) (c) Stephan Slabihoud 1995\n\n\n");
fprintf(stderr,"Usage: mkrawidx <lst1> [<lst2> [...]]\n");
getch();
exit(2);
}
printf("MKRAWIDX V"VERSION" Nodelist-Utility (Demo) (c) Stephan Slabihoud 1995\n\n\n");
/*
** Open output file
*/
fp=fopen("NODELIST.RDX","wb");
/*
** Create header. Note: header.version is 0x0001 !
*/
header.version=0x0001;
time(&(time_t)header.datetime);
header.nodelists=argc; /* number of nodelists */
header.flag=0; /* output is unsorted */
fwrite(&header,sizeof(HEADER),1,fp);
/*
** Now write all Nodelist-Header...
*/
for (i=1; i<=header.nodelists; i++)
{ nlheader.type=0; /* only nodelists in that demo */
nlheader.day=0; /* Not yet implemented */
*nlheader.network='\0'; /* Not yet implemented */
strcpy(nlheader.file,argv[i]); /* filename */
fwrite(&nlheader,sizeof(NLHEADER),1,fp);
}
/*
** ...and all nodelist entries
*/
for (i=0; i<header.nodelists; i++)
parse_list(fp,argv[i+1],i,0,FALSE);
fclose(fp);
return(0);
}
/*
** defzone is not yet used. This parameter is neccessary when
** including a 3d pointlist.
** pointlist must be TRUE when parsing a pointlist and otherwise FALSE
*/
static uword parse_list(FILE *fp,ubyte *src,uword nlnumber,uword defzone,uword pointlist)
{ uword zone=0,net=0,node=0,point=0;
ulong counter=0,offset=0;
FILE *in;
ubyte line[256],*pointer,*pointer2;
entry.nodelist=nlnumber;
in = fopen(src,"rb");
setvbuf(in ,NULL,_IOFBF,32768U);
printf("\nConverting... %lu\r",counter);
if (pointlist)
zone=defzone;
fgets(line,256,in);
while (!feof(in))
{ if (*line!=';')
{
if (!strnicmp(line,"zone",4))
{ zone=atoi(strchr(line,',')+1);
node=point=0;
net=zone;
new_entry(fp,offset,zone,net,node,point);
}
else if (!strnicmp(line,"region",6))
{ net=atoi(strchr(line,',')+1);
node=point=0;
if (!pointlist)
new_entry(fp,offset,zone,net,node,point);
}
else if (!strnicmp(line,"host",4))
{ pointer=strchr(line,',');
if (pointlist)
{ pointer2=strchr(pointer+1,',');
net=atoi(pointer2+1);
pointer2=strchr(pointer2+1,'/');
if (pointer2==NULL)
{ net=atoi(line+5); /* ERROR: use Fakenet */
node=0;
}
else
node=atoi(pointer2+1);
}
else
{ net=atoi(pointer+1);
}
point=0;
new_entry(fp,offset,zone,net,node,point);
}
else if ( *line==',' ||
strnicmp(line,"hub",3)==0 ||
strnicmp(line,"down",4)==0 ||
strnicmp(line,"hold",4)==0 ||
strnicmp(line,"pvt",3)==0 )
{ pointer=strchr(line,',');
if (pointlist)
{ point=atoi(pointer+1);
if (!node)
{ node=point;
point=0;
}
}
else
{ node=atoi(pointer+1);
}
new_entry(fp,offset,zone,net,node,point);
}
}
counter++;
if (!(counter & 0xff))
printf("Converting... %lu\r",counter);
offset=ftell(in);
fgets(line,256,in);
}
printf("Converted.... %lu names\n\n",counter);
fclose(in);
return(0);
}
static void new_entry(FILE *out,ulong offset,uword zone,uword net,uword node,uword point)
{ entry.zone=zone;
entry.net=net;
entry.node=node;
entry.point=point;
entry.offset=offset;
entry.f_flags=0; /* Not yet implemented */
entry.m_flags=0; /* Not yet implemented */
fwrite(&entry,sizeof(ENTRY),1,out);
}